package com.monster.servlet;

import com.alibaba.fastjson.JSONArray;
import com.monster.pojo.Singer;
import com.monster.service.ListServiceImpl;
import com.monster.service.SingerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;


@WebServlet( "/IndexSongsServlet")
public class IndexSongsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        SingerService singerService = new ListServiceImpl();
        PrintWriter out = response.getWriter();
        String area = request.getParameter("area");
        if(area.equals("1")){
            area = "内地";
        }
        if(area.equals("2")){
            area = "港台";
        }
        if(area.equals("3")){
            area = "欧美";
        }
        if(area.equals("4")){
            area = "日本";
        }
        if(area.equals("5")){
            area = "韩国";
        }

        String no = request.getParameter("page");
        int page = Integer.parseInt(no);
        ArrayList<Singer> sList = new ArrayList<>();
        sList = singerService.getSingersSongsByArea(area,page);
        out.print(JSONArray.toJSON(sList));
        out.flush();
        out.close();
    }
}
